#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
int count(int n)
{
    stringstream ss;
    string s;
    ss<<setw(4)<<setfill('0')<<n;
    ss>>s;
    //cout<<s;
    string s1;
    for(auto e:s)
    {
        if(s1.find(e) == -1)
            s1.push_back(e);
    }
    return s1.size();
    
}
int main()
{
    int start,num;
    cin>>start>>num;
    int cur = start;
    while(true)
    {
        
        if(count(cur) == num)
        {
            cout<<setw(1)<<(cur-start)<<" "<<setw(4)<<setfill('0')<<cur;
            break;
        }
        else
            cur++;
    }
}